package org.istt.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * Category entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "TBL_CATEGORY", schema = "dbo", catalog = "onegate"/*,uniqueConstraints=
	@UniqueConstraint(columnNames={"CATEGORY_NAME"})*/)
public class Category extends BaseObject<Long> implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 7751024716639839527L;
	private Field field;
	private Workflow workflow;
	private String categoryName;
	private String shortName;
	private String description;
	private Set<File> files = new HashSet<File>(0);
	private Set<AttachFile> attachFiles = new HashSet<AttachFile>(0);
	//NDTHO.
	private Integer	feeNew;
	private Integer	feeChange;
	private String code;
	//NDTHO. 2011.11.01
	private Boolean isViewOnnet;
	private Boolean isRegisterOnnet;
	
	//NDTHO.2012.03.08
	private String processTime;
	
	private Report report;
	private Report voucher;
	
	private Set<SubCategory> subCategories = new HashSet<SubCategory>(0);
	
	// Constructors

	/** default constructor */
	public Category() {
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "FIELD_ID")
	public Field getField() {
		return this.field;
	}
	
	public void setIsViewOnnet(Boolean isViewOnnet) {
		this.isViewOnnet = isViewOnnet;
	}
	@Column(name = "IS_VIEW_ONNET", length = 1)
	public Boolean getIsViewOnnet() {
		return isViewOnnet;
	}

	public void setIsRegisterOnnet(Boolean isRegisterOnnet) {
		this.isRegisterOnnet = isRegisterOnnet;
	}

	@Column(name = "IS_REGISTER_ONNET", length = 1)
	public Boolean getIsRegisterOnnet() {
		return isRegisterOnnet;
	}

	public void setField(Field field) {
		this.field = field;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "WORKFLOW_ID")
	public Workflow getWorkflow() {
		return this.workflow;
	}

	public void setWorkflow(Workflow workflow) {
		this.workflow = workflow;
	}

	@Column(name = "CATEGORY_NAME")
	public String getCategoryName() {
		return this.categoryName;
	}

	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	@Column(name = "DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "category")
	public Set<File> getFiles() {
		return this.files;
	}

	public void setFiles(Set<File> files) {
		this.files = files;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "category")
	public Set<AttachFile> getAttachFiles() {
		return this.attachFiles;
	}

	public void setAttachFiles(Set<AttachFile> attachFiles) {
		this.attachFiles = attachFiles;
	}

	@Column(name = "FEE_NEW")
	public Integer getFeeNew() {
		return feeNew;
	}

	public void setFeeNew(Integer feeNew) {
		this.feeNew = feeNew;
	}

	@Column(name = "FEE_CHANGE")
	public Integer getFeeChange() {
		return feeChange;
	}

	public void setFeeChange(Integer feeChange) {
		this.feeChange = feeChange;
	}

	@Column(name = "CODE")
	public String getCode() {
		return code;
	}
	
	@Column(name = "SHORT_NAME")
	public String getShortName() {
		return shortName;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
        .append("categoryName", this.categoryName)
		.append("description", this.description);

		return sb.toString();
	}

	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof Category)) return false;

		final Category ps = (Category) o;


        if (!getCategoryName().equals(ps.getCategoryName())) return false;

		return true;
	}

	public int hashCode() {
		int result;
		result = categoryName.hashCode();
		result = 29 * result;
		return result;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public void setProcessTime(String processTime) {
		this.processTime = processTime;
	}

	@Column(name = "PROCESS_TIME", length = 1000)
	public String getProcessTime() {
		return processTime;
	}

	public void setReport(Report report) {
		this.report = report;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "REPORT_ID")
	public Report getReport() {
		return report;
	}

	public void setVoucher(Report voucher) {
		this.voucher = voucher;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "VOUCHER_ID")
	public Report getVoucher() {
		return voucher;
	}

	public void setSubCategories(Set<SubCategory> subCategories) {
		this.subCategories = subCategories;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "category")
	public Set<SubCategory> getSubCategories() {
		return subCategories;
	}

	
}